#include <stdlib.h>
#include <stdio.h>
#include "DLinkStack.h"

//初始化
int DLStackInit(DLStack* s)
{
    return DLlistInit(&s->stack);
}

//销毁单链式栈
void DLStackDestroy(DLStack* s)
{
    DLlistDestroy(&s->stack);
}

//入栈
void DLStackPush(DLStack* s, ElementType element)
{
    DLlistInsertTail(&s->stack, element);
}

//出栈
ElementType* DLStackPop(DLStack* s)
{   if(s->stack.len == 0)
    {
        printf("the Stack is empty!\n");
        return NULL;
    }
    s->TopElement = s->stack.tail->data;
    DLlistRemoveByIndex(&s->stack, s->stack.len - 1);
    return &s->TopElement; 
}

//获取栈顶元素
ElementType DLStackGetTop(DLStack* s)
{
    return s->stack.tail->data;
}

//判断栈是否为空
int DLStackIsEmpty(DLStack* s)
{
    if(s->stack.len == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//打印
void DLStackPrint(DLStack* s)
{
    DLlistPrint(&s->stack);
}

//获取队列有效元素个数
int LQueueSize(DLStack* s)
{
    return s->stack.len;
}
